package com.tax.plan.utils;

import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfPage;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
import com.itextpdf.kernel.pdf.canvas.parser.PdfCanvasProcessor;
import com.itextpdf.kernel.pdf.canvas.parser.listener.IPdfTextLocation;
import com.itextpdf.kernel.pdf.canvas.parser.listener.RegexBasedLocationExtractionStrategy;
import com.sun.xml.internal.bind.v2.util.ByteArrayOutputStreamEx;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

/**
 * pdf 填充
 *
 * @Author: TG
 * @Description: About this class
 * @Date :Created in 10:01 2021/5/24 0024
 * @Version : 1.0
 */
public class PdfItextReplaceUtil {
    /**
     * 填充PDF
     *
     * @param contractTemplateIns
     * @param dataStore
     * @return
     * @throws IOException
     */
    public static ByteArrayOutputStream fill(InputStream contractTemplateIns, Map<String, String> dataStore) throws IOException {
        PdfReplaceHandler pdfReplaceHandler = new DefaultPdfReplaceHandler();
        PdfReplaceDataStore pdfReplaceDataStore = new MapPdfReplaceDataStore(dataStore);
        return pdfReplaceHandler.fill(contractTemplateIns, pdfReplaceDataStore);
    }


}
